package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.Gcwx_Bxdj;
import com.htandroid.htandroid.entity.Gcwx_Places;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLGcwxBxdjlist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<Gcwx_Bxdj> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("Gcwx_Bxdj=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<Gcwx_Bxdj> cwxdjlist = new ArrayList<Gcwx_Bxdj>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{ID", "{\"ID"));
            try {
                Gcwx_Bxdj info = new Gcwx_Bxdj();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setID(string2null(dataJson.getString("ID")));
                info.setCdjcode(string2null(dataJson.getString("cdjcode")));
                info.setCdjname(string2null(dataJson.getString("cdjname")));
                info.setCpri(string2null(dataJson.getString("cpri")));
                info.setCshowcolor(string2null(dataJson.getString("cshowcolor")));
                info.setCmemo(string2null(dataJson.getString("cmemo")));
                cwxdjlist.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return cwxdjlist;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
